package com.mp.dao;

import org.apache.ibatis.session.RowBounds;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.baomidou.mybatisplus.plugins.Page;
import com.mp.entity.Employee;
import com.mp.mapper.UserMapper;

//进行物理分页
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-dao.xml")
public class TestPhysicalPage {
	@Autowired
	private UserMapper userMapper;
	@Test
	public void test() {
		//SELECT id AS id,username,`password` FROM user LIMIT 0,2
		//此时sql中会有limit，属于物理分页
		RowBounds rowBounds = new RowBounds(0,2);
		userMapper.selectPage(rowBounds, null);
		
		//使用ActiveRecord的分页
		Employee employee = new Employee();
		Page<Employee> page = new Page<Employee>(0,2);
		employee.selectPage(page, null); 
		//分页里面的相关数据都在page里面
		System.out.println("======相关的分页信息========");
		System.out.println("总页数："+page.getPages());
		System.out.println("总条数："+page.getTotal());
		System.out.println("当前页码："+page.getCurrent());
		System.out.println("每页显示的条数："+page.getSize());
		System.out.println("是否有上一页"+page.hasPrevious());
		System.out.println("是否有下一页："+page.hasNext());
	}
}
